package com.coffee.mycoffee.config.swaggerConfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * swagger使用步骤
 * 1.引入依赖
 * 2.主引导类添加@ComponentScan("com.abu")和@EnableSwagger2注解
 */
@EnableOpenApi
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        Docket docket = new Docket(DocumentationType.OAS_30);
        docket
                .groupName("service")
                .apiInfo(apiInfo())
                .select()
                .paths(PathSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.coffee"))
                .build()
                .enable(true);      //是否启动swagger
        return docket;
    }

    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .contact(new Contact("咖啡", "http://www.baidu.com", "@qq.com"))
                .description("这是一个自建的微服务项目")
                .title("用户中心微服务")
                .version("1.0.1")
                .license("无")
                .build();
    }
}
